package main

import (
	"fmt"
	"math"
	"math/rand"
	"time"
)

func main() {
	// 1. 打印九九乘法表。如果可以要求间隔均匀。
	for i := 1; i <= 9; i++ {
		for j := 1; j <= i; j++ {
			info := fmt.Sprintf("%d*%d=%d", i, j, i*j)
			fmt.Printf("%-7s", info)
		}
		fmt.Println()
	}

	// 2. 随机生成20以内的20个非0正整数，打印出来。对生成的数值，第单数个（不是索引）累加求和，第偶数个累乘求积。打印结果
	sum := 0
	product := 1
	r := rand.New(rand.NewSource(time.Now().UnixNano()))

	for i := 0; i <= 20; i++ {
		number := r.Intn(20) + 1
		if math.Mod(float64(i), 2) < 1 {
			sum += number
		} else {
			product *= number
		}
		fmt.Printf("%d ", number)
	}
	fmt.Printf("随机数奇数个求和:%d 偶数个求积:%d\n", sum, product)

	// 3. 打印100以内的斐波那契数列
	first := 1
	second := 1
	fmt.Printf("斐波那契数列：%d %d", first, second)

	for first+second < 100 {
		first, second = second, first+second
		fmt.Printf(" %d", second)
	}

}
